package com.testmanager.testmananger.shuiyou.szjk.service;


import com.testmanager.testmananger.shuiyou.szjk.domain.ZipFileEntity;
import com.testmanager.testmananger.shuiyou.szjk.domain.ZipTypeEntity;
import com.testmanager.testmananger.shuiyou.szjk.repository.ZipTypeRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class ZipTypeService {

    @Autowired
    ZipTypeRepository zipTypeRepository;

    public ResponseEntity<List<ZipTypeEntity>> getZipTypes(){
        return ResponseEntity.ok(zipTypeRepository.findAll());
    }

    public ResponseEntity<List<ZipTypeEntity>> saveZipType(ZipTypeEntity zipTypeEntity){
        log.info("save ziptypeentity {}",zipTypeEntity);
        zipTypeRepository.save(zipTypeEntity);

        return  ResponseEntity.ok(zipTypeRepository.findAll());

    }

    public ResponseEntity saveZipTypes(List<ZipTypeEntity> zipTypeEntities){
        log.info("save ziptypes :{}",zipTypeEntities);

        zipTypeEntities.stream()
                .forEach(zipTypeEntity -> {
                    saveZipType(zipTypeEntity);
                });

        return  ResponseEntity.ok(zipTypeRepository.findAll());
    }




}
